﻿using Grow.Module;
using Grow.Utils.Exceptions;
using Grow.Utils.Extensions;

namespace Grow.AspNetCore
{
    public class DependModuleBuilder : IDependModuleBuilder
    {
        private readonly IModuleBuilder _moduleBuilder;
        public DependModuleBuilder(IModuleBuilder moduleBuilder)
        {
            _moduleBuilder = moduleBuilder;
        }
        public IDependModuleBuilder AddDependModule<TModule>() where TModule : IModule
        {
            return !_moduleBuilder.GetModules().Where(x => x.GetType().IsAssignableFrom<TModule>()).Any()
                ? throw new GrowFrameworkException($"类型为“{typeof(TModule).FullName}”的模块类别无法找到")
                : (IDependModuleBuilder)this;
        }
    }
}
